<%@ page language="java" import="com.demo.util.Conn,java.sql.ResultSet" pageEncoding="UTF-8"%>
<%
String success = "student/index.jsp";

String errMsg = request.getParameter("errmsg");
errMsg = errMsg == null ? "" : errMsg;
String login = "";
String pwd = "";
String type = "";
Conn conn = new Conn();

if ("POST".equals(request.getMethod())) {
	login = request.getParameter("login");
	pwd = request.getParameter("pwd");
	type = request.getParameter("type");
	
	StringBuffer sql = new StringBuffer();
	if("1".equals(type)){
		sql.append("select * from " + "dbf_stuuser" + " where login='" + login + "'");
		sql.append(" and password='" + pwd + "'");
		
		ResultSet rs = conn.find(sql.toString());
		if (null != rs && rs.next()) {
			session.setAttribute("user_id", rs.getString("STUUSER_ID"));
			session.setAttribute("user_name", rs.getString("name"));
			session.setAttribute("user_type", type);
			response.sendRedirect(success);
		} else {
			errMsg = "Incorrect Login or Password!";
		}
		rs.close();
	}
	else if("2".equals(type)){
		success="company/index_com.jsp";
		sql.append("select * from " + "dbf_user_company" + " where login_name='" + login + "'");
		sql.append(" and password='" + pwd + "'");
		
		ResultSet rs = conn.find(sql.toString());
		if (null != rs && rs.next()) {
			session.setAttribute("user_id", rs.getString("company_id"));
			session.setAttribute("user_name", rs.getString("login_name"));
			session.setAttribute("user_type", type);
			response.sendRedirect(success);
		} else {
			errMsg = "incorrect Login or Password!";
		}
		rs.close();
	}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Login</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<link rel="stylesheet" type="text/css" href="style.css">
    <style type="text/css">
<!--
.logintxt {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; }
.errMsg {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; color:red; }
a:link {
	color: #333333;
}
a:visited {
	color: #333333;
}
a:hover {
	color: #FF9900;
}
a:active {
	color: #333333;
}
.style4 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color:#666666 }
-->
    </style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
  
  <body>

	  	<table width="916" border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td width="321" valign="top"><table width="223" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="3"><img src="images/login_menu1.jpg" width="320" height="39"></td>
              </tr>
              <tr>
                <td width="19" background="images/menu_4.jpg"><img src="images/menu_c1.jpg" width="19" height="54"></td>
                <td width="290" valign="top" bgcolor="#FFFFFF"><form action="login.jsp" method="post" style="margin:0px">
                  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="28%">&nbsp;</td>
                      <td width="72%" align="left" class="logintxt">&nbsp;</td>
                    </tr>
                    <tr>
                      <td><div align="right"><span class="logintxt">Login:&nbsp;</span></div></td>
                      <td align="left" class="logintxt"><div align="center">
                        <input name="login" type="text" class="logintxt" id="login" style="width:150px;" value="<%=login %>"/>
                      </div></td>
                    </tr>
                    <tr>
                      <td><div align="right"><span class="logintxt">Password:&nbsp;</span></div></td>
                      <td align="left" class="logintxt"><div align="center">
                        <input name="pwd" type="password" class="logintxt" id="pwd" style="width:150px;" value="<%=pwd %>"/>
                      </div></td>
                    </tr>
                    <tr>
                      <td colspan="2"><img src="images/spacer.jpg" width="2" height="9"></td>
                    </tr>
                    <tr>
                      <td colspan="2" class="logintxt"><div align="center">
                          <input type="radio" value="1" name="type" <%=!"2".equals(type) ? "checked" : "" %>/>
                        Student&nbsp;&nbsp;
                        <input type="radio" value="2" name="type" <%="2".equals(type) ? "checked" : "" %>/>
                        Corporate&nbsp;&nbsp; </div></td>
                    </tr>
                    <tr>
                      <td colspan="2" style="color:red;text-align:center"><img src="images/spacer.jpg" width="2" height="9"></td>
                    </tr>
                    <tr class="logintxt">
                      <td height="15" colspan="2" class="errMsg"><div align="center"><%=errMsg %></div></td>
                    </tr>

                    <tr>
                      <td colspan="2"><div align="center"><span class="logintxt"><a href="student/reg.jsp">Student Registration</a> &nbsp;<a href="company/reg.jsp">Corporate Registration</a></span> </div></td>
                    </tr>
					
                    <tr>
                      <td colspan="2"><img src="images/spacer.jpg" width="2" height="9"></td>
                    </tr>
                    <tr>
                      <td height="45"><img src="images/logo.gif" width="46" height="45"></td>
                      <td height="45">
                        <div align="right">
                          <input name="submit2" type="image" src="images/login_btn.jpg" value="submit" />
                      </div></td>
                    </tr>
                  </table>
                </form></td>
                <td width="18" background="images/menu_d1.jpg"><img src="images/menu_d1.jpg" width="18" height="54" /></td>
              </tr>
              <tr>
                <td><img src="images/menu_e1.jpg" width="19" height="25"></td>
                <td><img src="images/menu_f1.jpg" width="283" height="25"></td>
                <td><img src="images/menu_g1.jpg" width="18" height="25"></td>
              </tr>
            </table>
              <table width="223" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="3"><img src="images/login_menu2.jpg" width="320" height="39" /></td>
                </tr>
                <tr>
                  <td width="19" background="images/menu_4.jpg"><img src="images/menu_c1.jpg" width="19" height="54" /></td>
                  <td width="290" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0">

                    <tr>
                      <td align="center"><form action="student/psearch.jsp">
                          <table border="0" cellspacing="0" cellpadding="0" width="100%">
                            <tr>
                              <td align="right" class="logintxt">&nbsp;</td>
                              <td align="center">&nbsp;</td>
                            </tr>
                            <tr>
                              <td align="right" class="logintxt">Company：</td>
                              <td align="center"><input type="text" name="companyname" /></td>
                            </tr>
                            <tr>
                              <td align="right" class="logintxt">Post Date ：</td>
                              <td align="center"><select name="jsd" class="logintxt" id="jsd">
                                  <option value=" ">----------- Please Select -----------</option>
                                  <option value="-1">--1 Day--</option>
                                  <option value="-7">--1 Week--</option>
                                  <option value="-30">--1 Month--</option>
                                </select>                              </td>
                            </tr>
                            <tr>
                              <td align="right" class="logintxt">Job Post：</td>
                              <td align="center"><input type="text" name="jtitle" /></td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center">&nbsp;</td>
                            </tr>
                            <tr>
                              <td colspan="2" align="center"><input name="image2" type="image" value="搜索" src="images/search_btn.jpg" /></td>
                            </tr>
                          </table>
                      </form></td>
                    </tr>
                  </table></td>
                  <td width="18" background="images/menu_d1.jpg"><img src="images/menu_d1.jpg" width="19" height="54" /></td>
                </tr>
                <tr>
                  <td><img src="images/menu_e1.jpg" width="19" height="25" /></td>
                  <td><img src="images/menu_f1.jpg" width="283" height="25" /></td>
                  <td><img src="images/menu_g1.jpg" width="18" height="25" /></td>
                </tr>
              </table>
              <table width="223" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td colspan="3"><img src="images/login_menu3.jpg" width="320" height="39" /></td>
                </tr>
                <tr>
                  <td width="19" background="images/menu_4.jpg"><img src="images/menu_c1.jpg" width="19" height="54" /></td>
                  <td width="290" valign="top" bgcolor="#FFFFFF"><form action="company/searchResumes.jsp">
                            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                              <tr>
                                <td align="right" class="logintxt">&nbsp;</td>
                                <td align="center">&nbsp;</td>
                              </tr>
                              <tr>
                                <td align="right" class="logintxt">Job Target：</td>
                                <td align="center"><input type="text" name="job_target" /></td>
                              </tr>
                              <tr>
                                <td align="right" class="logintxt">School：</td>
                                <td align="center"><input type="text" name="university" /></td>
                              </tr>
                              <tr>
                                <td align="right" class="logintxt">Degree：</td>
                                <td align="center"><input type="text" name="degree" /></td>
                              </tr>
                              <tr>
                                <td colspan="2" align="center">&nbsp;</td>
                              </tr>
                              <tr>
                                <td colspan="2" align="center"><input name="image" type="image" value="搜索" src="images/search_btn.jpg" /></td>
                              </tr>
                            </table>
                        </form></td>
                  <td width="18" background="images/menu_d1.jpg"><img src="images/menu_d1.jpg" width="19" height="54" /></td>
                </tr>
                <tr>
                  <td><img src="images/menu_e1.jpg" width="19" height="25" /></td>
                  <td><img src="images/menu_f1.jpg" width="283" height="25" /></td>
                  <td><img src="images/menu_g1.jpg" width="18" height="25" /></td>
                </tr>
              </table>              </td>
            <td width="568" valign="top"><table width="568" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="39" colspan="3" background="images/blank2_title.jpg"><table width="95%" border="0" align="center" cellpadding="5" cellspacing="0">
                    <tr>
                      <td><strong><span class="menutitle">Job Recruitment News</span></strong></td>
                      <td><div align="right"><strong><span class="menutitle"><a href="student/psearch.jsp" class="logintxt">more</a></span></strong></div></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td valign="bottom"><img src="images/menu_a.jpg" width="19" height="23" /></td>
                <td valign="top">&nbsp;</td>
                <td valign="bottom"><img src="images/menu_b.jpg" width="18" height="23" /></td>
              </tr>
              <tr>
                <td width="19" valign="top" background="images/menu_c.jpg"><img src="images/menu_c.jpg" width="19" height="54" /></td>
                <td valign="top"><table border="0" cellspacing="0" cellpadding="0" width="100%">
                  <%
  						String sql = "select * from dbf_job_info order by JOB_STARTING_DATE desc limit 0,10";
	  					ResultSet rsj = conn.find(sql);
  						while(rsj.next()) { 
  						%>
                  <tr>
                    <td class="logintxt"><%=rsj.getString("company_name")==null ? "" : rsj.getString("company_name") %></td>
                    <td class="logintxt"><a href="student/job_info.jsp?job_id=<%=rsj.getString("job_id") %>"><%=rsj.getString("job_title")==null ? "" : rsj.getString("job_title") %></a></td>
                    <td class="logintxt"><%=rsj.getString("persion_num")==null ? "" : rsj.getString("persion_num") %></td>
                    <td class="logintxt"><%=rsj.getString("job_starting_date")==null ? "" : rsj.getString("job_starting_date") %></td>
                    <td class="logintxt"><%=rsj.getString("application_deadline")==null ? "" : rsj.getString("application_deadline") %></td>
                  </tr>
                  <%} %>
                </table></td>
                <td width="18" valign="top" background="images/menu_d.jpg"><img src="images/menu_d.jpg" width="18" height="54" /></td>
              </tr>
              <tr>
                <td><img src="images/menu_e.jpg" width="19" height="25" /></td>
                <td background="images/menu_f.jpg"><img src="images/menu_f.jpg" width="181" height="25" /></td>
                <td><img src="images/menu_g.jpg" width="18" height="25" /></td>
              </tr>

            </table>
              <table width="568" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="39" colspan="3" background="images/blank2_title.jpg"><table width="95%" border="0" align="center" cellpadding="5" cellspacing="0">
                      <tr>
                        <td><strong><span class="menutitle">Registered Corporate</span></strong></td>
                        <td><div align="right"><strong><span class="menutitle"><a href="admin/company.jsp" class="logintxt">more</a></span></strong></div></td>
                      </tr>
                  </table></td>
                </tr>
                <tr>
                  <td valign="bottom"><img src="images/menu_a.jpg" width="19" height="23" /></td>
                  <td valign="top">&nbsp;</td>
                  <td valign="bottom"><img src="images/menu_b.jpg" width="18" height="23" /></td>
                </tr>
                <tr>
                  <td width="19" valign="top" background="images/menu_c.jpg"><img src="images/menu_c.jpg" width="19" height="54" /></td>
                  <td valign="top"><table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <%
  						sql = "select * from dbf_user_company where corp_name_chs is not null limit 0,10";
	  					ResultSet rsc = conn.find(sql);
  						while(rsc.next()) { 
  						System.out.println(rsc.getString("corp_name_en"));
  						%>
                    <tr class="logintxt">
                      <td><%=(rsc.getString("corp_name_chs")==null ? " " : rsc.getString("corp_name_chs")) 
  									+ (rsc.getString("corp_name_en")==null || "".equals(rsc.getString("corp_name_en")) ? 
  									" " : ("(" + rsc.getString("corp_name_en") + ")")) %> </td>
                    </tr>
                    <%} %>
                  </table></td>
                  <td width="18" valign="top" background="images/menu_d.jpg"><img src="images/menu_d.jpg" width="18" height="54" /></td>
                </tr>
                <tr>
                  <td><img src="images/menu_e.jpg" width="19" height="25" /></td>
                  <td background="images/menu_f.jpg"><img src="images/menu_f.jpg" width="181" height="25" /></td>
                  <td><img src="images/menu_g.jpg" width="18" height="25" /></td>
                </tr>
              </table>
              <table width="568" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td height="39" colspan="3" background="images/blank2_title.jpg"><table width="95%" border="0" align="center" cellpadding="5" cellspacing="0">
                      <tr>
                        <td><strong><span class="menutitle">Registered Students</span></strong></td>
                        <td><div align="right"><strong><span class="menutitle"><a href="company/searchResumes.jsp" class="logintxt">more</a></span></strong></div></td>
                      </tr>
                  </table></td>
                </tr>
                <tr>
                  <td valign="bottom"><img src="images/menu_a.jpg" width="19" height="23" /></td>
                  <td valign="top">&nbsp;</td>
                  <td valign="bottom"><img src="images/menu_b.jpg" width="18" height="23" /></td>
                </tr>
                <tr>
                  <td width="19" valign="top" background="images/menu_c.jpg"><img src="images/menu_c.jpg" width="19" height="54" /></td>
                  <td valign="top"><table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <%
  						sql = "select job.job_title,u.name,u.sex,u.job_target from dbf_application_info";
  						sql = sql + " app left join dbf_job_info job on app.job_id = job.job_id ";
  						sql = sql + " left join dbf_stuuser u on app.user_id = u.stuuser_id order by ";
  						sql = sql + "app.APPLICATION_DATE desc limit 0,10";
	  					ResultSet rsa = conn.find(sql);
  						while(rsa.next()) { 
  						%>
                    <tr class="logintxt">
                      <td><%=(rsa.getString("name")==null ? "" : rsa.getString("name")) + " | " 
  										+ (rsa.getString("sex")==null ? "" : rsa.getString("sex")) + " | " 
  										+ (rsa.getString("job_target")==null ? "" : rsa.getString("job_target")) 
  										+ " 应聘：" + (rsa.getString("job_title")==null ? "" : rsa.getString("job_title")) %> </td>
                    </tr>
                    <%} %>
                  </table></td>
                  <td width="18" valign="top" background="images/menu_d.jpg"><img src="images/menu_d.jpg" width="18" height="54" /></td>
                </tr>
                <tr>
                  <td><img src="images/menu_e.jpg" width="19" height="25" /></td>
                  <td background="images/menu_f.jpg"><img src="images/menu_f.jpg" width="181" height="25" /></td>
                  <td><img src="images/menu_g.jpg" width="18" height="25" /></td>
                </tr>
              </table>              </td>
          </tr>
          <tr>
            <td valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
  </table>
	  	<p>&nbsp;</p>
  	    </body>
</html>
